<template>
  <div class="card" style="padding: 20px; width: 50%; margin: 10px auto">
    <div style="font-weight: bold; font-size: 24px; margin-bottom: 40px">系统公告</div>
    <el-timeline style="max-width: 600px">
      <el-timeline-item
          v-for="(item, index) in data.notice"
          :key="index"
          :icon="item.icon"
          :type="item.type"
          :color="item.color"
          :size="item.size"
          :hollow="item.hollow"
          :timestamp="item.time"
      >
        {{ item.content }}
      </el-timeline-item>
    </el-timeline>
  </div>
</template>

<script setup>
  import { reactive } from 'vue'
  import request from '@/utils/request.js'
  import { ElMessage } from 'element-plus'

  const data = reactive({
    user: JSON.parse(localStorage.getItem('xm-user') || '{}'),
    notice: []
  })

  const loadNotice = () => {
    request.get('/notice/query/all').then(res => {
      if (res.code === '200') {
        data.notice = res.data
      } else {
        ElMessage.error(res.msg)
      }
    })
  }

  loadNotice()
</script>